package com.android.presenter.info;

import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.util.log.LogUtil;
import com.android.model.info.UserModel;
import com.android.model.entity.res.LoginResult;
import com.android.presenter.iview.ILoginView;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 登陆
 */

public class LoginPresenter extends BasePresenter<ILoginView> {

    private static final String TAG = LoginPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public LoginPresenter(ILoginView iLoginView) {
        super(iLoginView);
        mUserModel = UserModel.getInstance();
    }

    public void getLoginStatus(String phone, String password, String codeType) {
        mUserModel.getLoginStatus(phone, password, codeType, new HttpObserver<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                LogUtil.e(TAG, "请求登陆成功");
                if (mIView != null) {
                    mIView.loginSuccess(loginResult);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.loginFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
